<!--评论显示-->
<?php
//header("location:clickUp.php?newsId=".$_GET['newsId']);
$conn=new mysqli("localhost","root","123456","htmlkeshe");
$conn->query("set names utf8");

$sql="SELECT * FROM comment where newsId='".$_GET['newsId']."'";
$result=$conn->query($sql);

//跳转页面所需的数据
$totalnum=mysqli_num_rows($result);//总数
$pagesize=5;//每页大小
$page=isset($_GET["page"])?$_GET["page"]:1;//如果传入page则读取第几页否则就是1
$begin=($page-1) * $pagesize;//数据库中字段开始位置 page在此处发生改变 具体页面没变 但是读取的数据改变了
$totalpage=ceil($totalnum/$pagesize);//页数

//所要展示的内容

//读取到我的新闻内容
$sql="SELECT * FROM comment where newsId='".$_GET['newsId']."' limit $begin,$pagesize";//limit从x开始多少个
$result=$conn->query($sql);
$datanum=mysqli_num_rows($result);
//输出该页所有评论
$listOut = "";
while ($row=$result->fetch_assoc()){
    $listOut .="<div class='pinglun_show_content'>
                      <div class='pinglun_show_content_name'>
                            <p>".$row['userName'].":</p>
                      </div>
                            <div class='pinglun_show_content_inner'>
                                <p>&nbsp&nbsp&nbsp&nbsp".$row['content']."</p>
                            </div>
               </div>";

}
echo $listOut;
//页面跳转部分
$pageOut="<div class='center_content_footer'>";
if($page>1)
{
    $pageOut.="<span onclick='showComment({$_GET['newsId']},$page-1)'> < </span>";
}

if($page<4) {
    for($j=1;$j<$page;$j++){
        $pageOut .= "<span onclick='showComment({$_GET['newsId']},$j)'> $j </span>";
    }
    for ($j = $page+1; $j <= min($totalpage, 7);$j++) {
        $pageOut .= "<span onclick='showComment({$_GET['newsId']},$j)'> $j </span>";
    }
}
elseif ($page>$totalpage-3)
{
    for($j=$totalpage-6;$j<$page;$j++){
        $pageOut .= "<span onclick='showComment({$_GET['newsId']},$j)'> $j </span>";
    }
    for($j = $page+1;$j<=$totalpage;$j++){
        $pageOut .= "<span onclick='showComment({$_GET['newsId']},$j)'> $j </span>";
    }
}
else{
    for($j=$page-3;$j<=$page+3;$j++){
        $pageOut .= "<span onclick='showComment({$_GET['newsId']},$j)'> $j </span>";
    }
}

if($page<$totalpage)
{
    $pageOut.="<span onclick='showComment({$_GET['newsId']},$page+1)'> > </span>";
}

$pageOut.="</div>";
echo $pageOut;
$conn->close();
?>


